package com.ipc.app.service.impl;

import java.util.LinkedList;
import java.util.List;

import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionTemplate;

import com.ipc.app.dal.dao.CarDAO;
import com.ipc.app.dal.doObject.CarDO;
import com.ipc.app.model.Car;
import com.ipc.app.service.CarInformationService;
import com.ipc.app.util.converter.CarConverter;

/**
 * @author 雪
 * 
 */
public class CarInformationServiceImpl implements CarInformationService {

	private CarDAO carDAO;

	private TransactionTemplate transactionTemplate;

	public void carInformationRelease(Car car) {
		transactionTemplate
				.setPropagationBehavior(DefaultTransactionDefinition.PROPAGATION_REQUIRED);
		transactionTemplate.execute(new TransactionCallback() {
			public Object doInTransaction(TransactionStatus arg0) {

				return null;
			}
		});
	}

	public List<Car> carList(String userId) {
		List<CarDO> carDOs = carDAO.getCarDOByUserID(userId);
		List<Car> cars = new LinkedList<Car>();
		for (CarDO carDO : carDOs) {
			Car car = CarConverter.carDOToCore(carDO);
			cars.add(car);
		}
		return cars;
	}

	public Car getCarByCarLincense(String carLicense) {
		CarDO carDO = carDAO.getCarDOByCarLicense(carLicense);
		Car car = CarConverter.carDOToCore(carDO);
		return car;
	}

	public void setCarDAO(CarDAO carDAO) {
		this.carDAO = carDAO;
	}

	public void setTransactionTemplate(TransactionTemplate transactionTemplate) {
		this.transactionTemplate = transactionTemplate;
	}

}
